package com.jrx.anytxn.accounting.job.consolidationcheck.step;

import com.jrx.anytxn.accounting.bean.ConsolidationCheckBean;
import com.jrx.anytxn.accounting.entity.GaVoucherExcpReport;
import com.jrx.anytxn.accounting.mapper.ext.ExtVoucherExcpReportMapper;
import org.springframework.batch.item.ItemWriter;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
 *  并账检查  - writer
 * @author Qingyao Xing
 * @date 2019/9/9 11:40
 */
@Service
public class ConsolidationCheckWriter  implements ItemWriter<ConsolidationCheckBean> {

    @Resource
    private ExtVoucherExcpReportMapper extVoucherExcpReportMapper;
    @Override
    public void write(List items) {

        List<GaVoucherExcpReport> interestVoucherExcpReportList = new ArrayList();
        for (Object item : items) {
            ConsolidationCheckBean bean=(ConsolidationCheckBean)item;
            if (!CollectionUtils.isEmpty(bean.getInterestVoucherExcpReportList())) {
                interestVoucherExcpReportList.addAll(bean.getInterestVoucherExcpReportList());
            }
        }

        if(!CollectionUtils.isEmpty(interestVoucherExcpReportList)) {
            extVoucherExcpReportMapper.batchInsert(interestVoucherExcpReportList);
        }
    }
}
